home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-21 | 5.6 KB | 222 lines | [TEXT/R*ch] |
- /*
- AppAEObj_pd.h
- © Bob Boylan 1996
-
- Revision History
- MacHack 1996 initial creation
- */
- #include "debug.h"
- #include "AppAEObj_pd.h"
- #include "PropertyValue_pd.h"
- #include "ComputerAEObj_pd.h"
- #include "Helpers_ut.h"
- #include "AEBuild.h"
-
- #include <string.h>
- #include <sstream>
-
-
-
- // -----------------------------------------------------------------
- // ctor
- //
- AppAEObj_pd::AppAEObj_pd( AEObj_pd * inParent, DescType inKind, Int_32 inIndex )
- : AEObj_pd( inParent, inKind, inIndex )
- {
- // get the finder info ... our parent is a computer
- _SizeofFinderAppAddr = inParent->GetSizeofAppAddr();
- dassert( _SizeofFinderAppAddr == sizeof(OSType) );
- memcpy( &_FinderAppAddr, inParent->GetAppAddr(), _SizeofFinderAppAddr );
- _FinderAppAddrType = inParent->GetAppAddrType();
- _HaveAppAddr = false;
-
- // we don't want to be using the computer aete
- Clone_ut< AETE_da > theClonedAETE;
- _AETE = theClonedAETE;
-
- }
-
- // -----------------------------------------------------------------
- // ctor from child
- //
- AppAEObj_pd::AppAEObj_pd( AEObj_pd * inChild )
- : AEObj_pd( inChild )
- {
- _HaveAppAddr = true;
- _AETE = inChild->GetAETE();
-
- memcpy( &_AppSignature, inChild->GetAppAddr(), inChild->GetSizeofAppAddr() );
-
- }
-
- // -----------------------------------------------------------------
- // dtor
- //
- AppAEObj_pd::~AppAEObj_pd()
- {}
- // -----------------------------------------------------------------
- // Update
- //
- void
- AppAEObj_pd::Update( ProgressProc_hi &inProgressProc, Int_32 inMaxSubModels )
- {
- // see if we need the app's aete ... we only get it when necessary
- if( _HaveAppAddr == false )
- {
- PropertyValue_pd theCreator = GetProcessPropertyValue('fcrt');
- if( (*theCreator._Value).mDesc.descriptorType == typeNull )
- {
- // dassert( false ); // app not there?
- }
- else
- {
- Handle theHandle = (*theCreator._Value).mDesc.dataHandle;
- _AppSignature = **(OSType**) theHandle;
- if( IsScriptable() == true )
- {
- IsValidAETE(); // force validation (kinda parasitic)
- _HaveAppAddr = true;
- }
-
- }
- }
-
- // ok, now that we have the application address we can proceed normally
- if( _HaveAppAddr == true )
- {
- AEObj_pd::Update( inProgressProc, inMaxSubModels );
- }
-
- }
-
- // -----------------------------------------------------------------
- // GetParent
- //
- Clone_ut< AEObj_pd >
- AppAEObj_pd::GetParent()
- {
- // our parent is always a computer
- AEObj_pd *theComputer = new ComputerAEObj_pd;
- Clone_ut<AEObj_pd> theClone( theComputer );
- return theClone;
- }
-
-
- // -----------------------------------------------------------------
- // GetProcessPropertyValue
- //
- PropertyValue_pd
- AppAEObj_pd::GetProcessPropertyValue( DescType inKind )
- {
- // ask the finder for this value
- ostringstream theStream( ios::in | ios::out );
- // create the aegizmo string
- theStream << "'----':obj {form:prop," <<
- "want:type(prop)," <<
- "seld:type(" << As4CharString( inKind ) << ")," <<
- "from:" <<
- "obj {want:type(pcap)," <<
- "form:indx,seld:" << _ObjectSpec.back()._Pos <<
- ",from:'null'()}" <<
- "}";
- OSErr theErr;
- StAEDescriptor theAppleEvent;
- // use gizmos to create the apple event
- theErr = AEBuildAppleEvent( kAECoreSuite, kAEGetData,
- GetFinderAppAddrType(),
- GetFinderAppAddr(),
- GetSizeofFinderAppAddr(),
- kAutoGenerateReturnID, kAnyTransactionID,
- &theAppleEvent.mDesc, theStream.str().c_str() );
- dassert( theErr == noErr );
-
- StAEDescriptor theReplyAppleEvent;
- // and off with it
- theErr = AESend( &theAppleEvent.mDesc, &theReplyAppleEvent.mDesc, kAEWaitReply,
- kAENormalPriority, kAEDefaultTimeout, nil, nil );
-
- // package up the return value
- StAEDescriptor *theResult = new StAEDescriptor;
- Clone_ut<StAEDescriptor> theVal( theResult );
- if( theErr == noErr )
- {
- theErr = AEGetParamDesc( theReplyAppleEvent, keyDirectObject, typeWildCard, &theResult->mDesc );
- }
- PropertyValue_pd theRetVal( inKind, theVal, string("") );
-
- return theRetVal;
-
- }
- // -----------------------------------------------------------------
- // GetFinderAppAddr
- //
- void *
- AppAEObj_pd::GetFinderAppAddr()
- {
- return &_FinderAppAddr;
- }
- // -----------------------------------------------------------------
- // GetFinderAppAddrType
- //
- OSType
- AppAEObj_pd::GetFinderAppAddrType()
- {
- return typeApplSignature;
- }
- // -----------------------------------------------------------------
- // GetSizeofFinderAppAddr
- //
- Int_32
- AppAEObj_pd::GetSizeofFinderAppAddr()
- {
- return sizeof(OSType);
- }
-
- // -----------------------------------------------------------------
- // IsScriptable
- //
- Boolean
- AppAEObj_pd::IsScriptable()
- {
- // ask the finder
- PropertyValue_pd isScriptableProp = GetProcessPropertyValue('isab');
- return AsBoolean( isScriptableProp );
- }
-
- // -----------------------------------------------------------------
- // IsValidAETE
- //
- Boolean
- AppAEObj_pd::IsValidAETE()
- {
- if( (_AETE.Isnil() == true) && (_HaveAppAddr == false) )
- {
- AETE_da *theAETE = new AETE_da( this );
- Clone_ut< AETE_da > theClonedAETE( theAETE );
- _AETE = theClonedAETE;
- }
- return !(_AETE.Isnil());
-
- }
-
- // -----------------------------------------------------------------
- // GetName
- //
- string
- AppAEObj_pd::GetName()
- {
- // our formal name
- ostringstream theStream( ios::in | ios::out );
- theStream << "App" << " # " << _ObjectSpec.back()._Pos ;
- _ObjectSpec.back()._FormalName = theStream.str();
-
- // and our regular name
- PropertyValue_pd theName = GetProcessPropertyValue(pName);
- if( (*theName._Value).mDesc.descriptorType != typeNull )
- {
- _ObjectSpec.back()._Name = Asstring( theName );
- theStream << string(" (") << _ObjectSpec.back()._Name << string(")");
- }
- return theStream.str();
- }
-